<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Vendor_object extends Base_object{
	
	private static $supported_bussiness_type = array(1=>'Food and drink', 2=>'sports');
	
	private static $public_search_field = array('id', 'name', 'vendor_code', 'business_type');

	private $id;
	private $name;
	private $vendor_code;
	private $business_type;
	private $primary_branch_id;
	

	public function __construct($id = null, $name = null, $vendor_code = null, $business_type = null, $primary_branch_id = null){
		$this->id = $id;
		$this->name = $name;
		$this->vendor_code = $vendor_code;
		$this->business_type = $business_type;
		$this->primary_branch_id = $primary_branch_id;
		parent::__construct($id);
	}
	public function getId(){
		return $this->id;
	}
	public function getVendorName(){
		return $this->name;
	}
	public function getVendorCode(){
		return $this->vendor_code;
	}
	public function getBusinessType(){
		return $this->business_type;
	}
	public static function getSupportedBusinessType(){
		return self::$supported_bussiness_type;
	}
	public static function getPublicSearchField(){
		return self::$public_search_field;
	}
	public function getContactsByType($contact_type){
		$mapper = ObjectMap_helper::getMapper('Contact_object');
		return $mapper->getContactByVendorAndType($this->id, $contact_type);
	}
	public function getPrimaryContact(){
		$result = $this->getContactsByType(Contact_object::PRIMARY_CONTACT);
		return $result[0];
	}
	public function getBranches(){
		$branches = ObjectMap_helper::getMapper('Branch_object')->findBySearchCriteria(array('vendors_id' => $this->id));
		foreach($branches as $key => $branch){
			if($branch->getId() == $this->primary_branch_id){
				unset($branches[$key]);
				array_unshift($branches, $branch);
			}
		}
		return $branches;	
	}
	public function getCoupons(){
		return ObjectMap_helper::getMapper('Coupons_object')->findBySearchCriteria(array('vendors_id' => $this->id));
	}
}